package high_scores;

import interfaces.IPlayer;

public class Player implements IPlayer {

	private String name;
	private String finishedTime;
	// private String difficultyLevel;

	/**
	 * Copy constructor
	 * 
	 * @param p - the player from witch to copy
	 */
	public Player(Player p) {
		if (p != null && isValidPlayer(p.getName(), p.getTime())) {
			this.name = p.getName();
			this.finishedTime = p.getTime();
		}
	}

	public Player(String name, String time) {
		if (isValidPlayer(name, time)) { // && difficulty != null
			this.name = name;
			// this.difficultyLevel = difficulty;
			this.finishedTime = time;
		}
	}

	private boolean isValidPlayer(String name, String time) {
		return name != null & name != "" && time != null && time.length() == 3;
	}

	@Override
	public String getName() {
		return this.name;
	}

	@Override
	public String getTime() {
		return this.finishedTime;
	}

	// @Override
	// public String getDifficultyLevel() {
	// return this.difficultyLevel;
	// }

	@Override
	public int compare(IPlayer player) {
		int player1Time = Integer.parseInt(getTime());
		int player2Time = Integer.parseInt(player.getTime());
		if (player1Time > player2Time)
			return 1;
		else if (player1Time == player2Time)
			return 0;
		else
			return -1;
	}
}
